﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ADC.DAL;

namespace ADC.BL
{
    public class ConsultingFactory
    {
        /// <summary>
        /// Get all visible
        /// </summary>
        /// <returns></returns>
        public static List<Consulting> GetAll()
        {
            var db = new dbADCEntities();
            return db.Consultings.Where(d => d.IsVisibled != null && d.IsVisibled == true).OrderByDescending(d => d.ModifiedDate).ToList();
        }

        public static List<Consulting> ListAll()
        {
            var db = new dbADCEntities();
            return db.Consultings.OrderByDescending(d => d.ModifiedDate).ToList();
        }

        public static Consulting GetByID(int consultingID)
        {
            var db = new dbADCEntities();
            return db.Consultings.Where(g => g.ConsultingID == consultingID).FirstOrDefault();
        }

        // Update Programe
        /// </summary>
        /// <param name="programe"></param>
        /// <returns></returns>
        public static int Update(Consulting tourInfo)
        {
            try
            {
                var db = new dbADCEntities();
                var objConsulting = new Consulting();
                objConsulting = db.Consultings.Where(g => g.ConsultingID == tourInfo.ConsultingID).FirstOrDefault();
                objConsulting.Title = tourInfo.Title;
                objConsulting.BodyDetails = tourInfo.BodyDetails;
                objConsulting.Body = tourInfo.Body;
                objConsulting.ModifiedBy = tourInfo.ModifiedBy;
                objConsulting.ModifiedDate = DateTime.Now;
                objConsulting.IsVisibled = tourInfo.IsVisibled;
                if (!string.IsNullOrEmpty(tourInfo.ImagePath))
                {
                    objConsulting.ImagePath = tourInfo.ImagePath;
                }

                return db.SaveChanges();
            }
            catch (Exception)
            {
                // Log here
                throw;
            }
        }

        public static int Delete(int consultingID)
        {
            var db = new dbADCEntities();

            // Delete Programe
            var tourInfo = db.Consultings.Where(g => g.ConsultingID.Equals(consultingID)).FirstOrDefault();
            db.DeleteObject(tourInfo);
            return db.SaveChanges();
        }

        public static Consulting Insert(Consulting tourInfo)
        {
            var db = new dbADCEntities();
            db.AddToConsultings((tourInfo));
            db.SaveChanges();
            return tourInfo;
        }
    }
}
